home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Win95 / Fun&Utils / GROUPS.ZIP / GROUPS.SM < prev    next >
Encoding:
Text File  |  1994-06-16  |  18.0 KB  |  647 lines

  1. /**************************************************************************************
  2. *  Group Transfer program
  3. *
  4. * (C) 1994 Rob Harford
  5. * Last Modified : 15 june 1994
  6. * 9/feb/94    - fixed problem with group names compising of other group names
  7. * 14/jun/1994 - fixed problem with spaces at the end of group names
  8. * 15/june/1994 - Added the 3d Dialog boxes
  9. * Release version 1.04
  10. ****************************************************************************************/
  11.  
  12. /***************************************************************************************
  13. * Delare sub routines to enable 3d Dialog boxes within script maker
  14. *
  15. ******************************************************************************************/
  16.  
  17.  
  18. declare function Ctl3dRegister lib "ctl3d.dll" (byval hInst as Long) as Integer
  19. declare function Ctl3dAutoSubClass lib "ctl3d.dll" (byval hInst as Long) as Integer
  20. declare function Ctl3dUnRegister lib "ctl3d.dll" (byval hInst as Long) as Integer
  21.  
  22.  
  23. /***************************************************************************************
  24. *    Function:  Encap$
  25. *    Parameters:Cmd$
  26. *    Purpose:    This routine encapusulates the groupname, to protect against spaces at
  27. *        the end or start of a group name
  28. *
  29. ******************************************************************************************/
  30.  
  31. function Encap$(groupname$)
  32.  Encap$=chr$(34)+groupname$+chr$(34)
  33. end function
  34.  
  35. /***************************************************************************************
  36. *    Function:  DDEexe
  37. *    Parameters:Cmd$
  38. *    Purpose:    This sub routine opens a DDE channel to the current shell, and then
  39. *        sends the command string ,held in Cmd$
  40. *
  41. ******************************************************************************************/
  42.  
  43. sub DDEexe(Cmd$)
  44.  
  45.     Dim DDEchannel as Integer
  46.  
  47.     DDEchannel = DDEInitiate("progman", "progman")
  48.     if DDEchannel = FALSE then 
  49.         MsgBox "Unable To Access Windows Shell. Either the primary Windows shell is not responding, or is incompatible with this script..", 16, "FATAL ERROR"
  50.     Else
  51.         DDEExecute DDEchannel, Cmd$ 
  52.         DDETerminate DDEchannel 
  53.     End If
  54. end sub
  55.  
  56. /* **************************************************************************************
  57. *    Function:    DDEget$
  58. *    Parameters:Cmd$
  59. *    Purpose:    This function opens a DDE channel to the current shell, then requests
  60. *        information based upon the contents of Cmd$
  61. *
  62. ******************************************************************************************/
  63. function DDEget$(g$)
  64.  
  65.     Dim DDEchannel as Integer
  66.  
  67.     DDEchannel = DDEInitiate("progman", "progman")
  68.     if DDEchannel = FALSE then 
  69.         MsgBox "Unable To Access Windows Shell. Either the primary Windows shell is not responding, or is incompatible with this script.", 16, "FATAL ERROR"
  70.     Else
  71.           DDEget$=DDErequest$(DDEchannel,g$)
  72.         DDETerminate DDEchannel 
  73.     end if
  74. end function
  75.  
  76.  
  77. /* **************************************************************************************
  78. *    Function:    DeleteItem
  79. *    Parameters:Group$
  80. *    Purpose:    This deletes an item from within a group from the shell
  81. *        e.g DeleteItem "File Manager"
  82. ******************************************************************************************/
  83.  
  84. sub DeleteItem (Group$)
  85.     Group$= "[ReplaceItem("+Group$+")]" 
  86.     DDEExe Group$ 
  87. End Sub
  88.  
  89. /* **************************************************************************************
  90. *    Function:    CreateGroup
  91. *    Parameters:Group$
  92. *    Purpose:    This creates a group from the shell
  93. *        e.g CreateGroup "Main"
  94. ******************************************************************************************/
  95.  
  96. sub CreateGroup (Group$)
  97.     Group$= "[CreateGroup("+CHR$(34)+Group$+CHR$(34)+", )]" 
  98.     DDEExe Group$ 
  99. End Sub
  100. /* **************************************************************************************
  101. *    Function:    MakeCompat$
  102. *    Parameters:Data$
  103. *    Purpose:    This untily removes brackets which may offend program manager.
  104. *
  105. ******************************************************************************************/
  106.  
  107.  
  108. function MakeCompat$(Data$)
  109.     
  110.     a=0
  111.  
  112.     Bad$="[]{}"
  113.     New$=""
  114.  
  115.     while (a<len(Data$))
  116.         a=a+1
  117.         c$=Mid$(Data$,a,1)
  118.         if (InStr(Bad$,c$)<>0) then
  119.             New$=New$+"."
  120.         else
  121.             New$=New$+c$
  122.         End if
  123.     Wend
  124.     MakeCompat$=New$
  125. end function
  126.  
  127. /* **************************************************************************************
  128. *    Function:    MakeComma$
  129. *    Parameters:Information$
  130. *    Purpose:    This converts the information received by GetGroups, and then adds 
  131. *        commas between each group name.
  132. *
  133. ******************************************************************************************/
  134.  
  135.  
  136. Function MakeComma$(Information$)
  137.  
  138.     a=1
  139.     mk$ =""
  140.     while (a<=Len(Information$))
  141.         if Mid$(Information$,a,1)=Chr$(13) then 
  142.             Mk$=Mk$ + ","
  143.             a=a+1
  144.         else
  145.             Mk$=Mk$ + Mid$(Information$,a,1)
  146.         End If
  147.         
  148.         a=a+1
  149.     Wend
  150.     MakeComma$=mk$
  151.  
  152. End Function
  153.  
  154. /* **************************************************************************************
  155. *    Function:    DeleteGroup
  156. *    Parameters:Group$
  157. *    Purpose:    This Deletes a group from the shell
  158. *        e.g DeleteGroup "Main"
  159. ******************************************************************************************/
  160.  
  161.  
  162. sub DeleteGroup (Group$)
  163.     GroupList$=MakeComma$(DDEget$("PROGMAN"))
  164.     GroupList$=","+GroupList$+","
  165.     If InStr(GroupList$,","+Group$+",")<>0 then
  166.         Group$= "[DeleteGroup("+CHR$(34)+Group$+CHR$(34)+")]" 
  167.         DDEExe Group$ 
  168.     end if
  169. End Sub
  170.  
  171. /* **************************************************************************************
  172. *    Function:    AddItem
  173. *    Parameters:Group$
  174. *    Purpose:    This adds a new item to the currently highlighted group
  175. *        AddItem "item data"
  176. *        e.g.
  177. *        AddItem Item$
  178. *    Items$ =Command Line including parameters+
  179. *        Title of icon+
  180. *        Icon Path+
  181. *        Icon Index (default is zero for the first index)+
  182. *        Xpos (position of icon on X axis)+
  183. *        Ypos (position of icon on Y axis)+
  184. *        Startup directory
  185. *
  186. *    Notes:The items "Command Line","Title os Icon" need to be enclosed within quotes
  187. *        Each item needs to seperated by a comma    
  188. ******************************************************************************************/
  189.  
  190. sub AddItem (Group$)
  191.     Group$= "[AddItem("+Group$+")]" 
  192.     DDEExe Group$ 
  193. End Sub
  194.  
  195. /* **************************************************************************************
  196. *    Function:    ShowGroup
  197. *    Parameters:Group$
  198. *    Purpose:    This brings a group to the front and highlights it
  199. *        e.g ShowGroup "Main"
  200. ******************************************************************************************/
  201.  
  202. sub ShowGroup(Group$)
  203.  
  204.     Group$="[ShowGroup("+Group$+")]"
  205.     DDEexe Group$ 
  206.  
  207. End Sub
  208.  
  209.  
  210. /* **************************************************************************************
  211. *    Function:    GetGroup$
  212. *    Parameters:NONE
  213. *    Purpose:    This returns a list of groups under your current shell
  214. *
  215. ******************************************************************************************/
  216.  
  217. Function GetGroup$()
  218.  
  219.     GetGroup$=DDEget("PROGMAN")
  220.  
  221. End Function
  222.  
  223.  
  224.  
  225.  
  226. /* **************************************************************************************
  227. *    Function:    MakeNDWValid$
  228. *    Parameters:Cmd$
  229. *    Purpose:   This converts the information received from the shell into a format
  230. *        acceptable to be sent back to the shell
  231. *
  232. ******************************************************************************************/
  233.  
  234. function MakeNDWValid$(Cmd$)
  235.  
  236.     Dim Comma1,Comma2,Comma3,Comma4 as integer
  237.     Dim Comma5,Comma6,Comma7,Comma8 as integer
  238.     Dim FileName$,Description$,IconFile$,StartDir$ as String    
  239.     dim IconPos as Long
  240.  
  241.     Comma1 = InStr(1,Cmd$,",")
  242.     Comma2 = InStr(Comma1+1,Cmd$,",")
  243.     Comma3 = InStr(Comma2+1,Cmd$,",")
  244.     Comma4 = InStr(Comma3+1,Cmd$,",")
  245.     Comma5 = InStr(Comma4+1,Cmd$,",")
  246.     Comma6 = InStr(Comma5+1,Cmd$,",")
  247.     Comma7 = InStr(Comma6+1,Cmd$,",")
  248.     Comma8 = InStr(Comma7+1,Cmd$,",")
  249.     
  250.     Description$ = MakeCompat$(Mid$(Cmd$,1,Comma1-1))
  251.     FileName$ = MakeCompat$(Mid$(Cmd$,Comma1+1,Comma2-Comma1-1))
  252.     StartDir$ = Mid$(Cmd$,Comma2+1,Comma3-Comma2-1)
  253.     IconFile$ = Mid$(Cmd$,Comma3+1,Comma4-Comma3-1)
  254.     x$ = Mid$(Cmd$,Comma4+1,Comma5-Comma4-1)
  255.     Y$ = Mid$(Cmd$,Comma5+1,Comma6-Comma5-1)
  256.     z$ = Mid$(Cmd$,Comma6+1,Comma7-Comma6-1)
  257.     H$ = Mid$(Cmd$,Comma7+1,Comma8-Comma7-1)
  258.     IconPos=val(z$)
  259.  
  260.     If (IconPos < 0) then 
  261.     ' Ndw is the shell, so we must add the magic number
  262.         IconPos=IconPos+32768
  263.     end if
  264.  
  265.     Cmd$=FileName$ +","+ Description$ +","+IconFile$+","+str$(IconPos)+","+x$+","+y$+","+StartDir$+","+h$
  266.     MakeNDWValid$=Cmd$
  267. end function
  268.  
  269.  
  270. /* **************************************************************************************
  271. *    Procedure:    InformUser
  272. *    Parameters:Cmd% , Comp$
  273. *    Purpose:    This allows the program to inform the user of what is happening
  274. *    Notes:    Legal command values:
  275. *            1= Open Window
  276. *            2= Update Message
  277. *            3= Close Windows
  278. *        Legel Comp values are 0-100
  279. ******************************************************************************************/
  280.  
  281. sub InformUser(Cmd%,Comp%)
  282.  
  283.     if Cmd%=1 then 'Create Window 
  284.         MsgOpen "Saving Group Information..Please Wait..",0,0,1,1900,2550
  285.     end If
  286.  
  287.     If Cmd%=2 then ' Update Thermometer
  288.         MsgSetThermometer Comp%
  289.     End if
  290.  
  291.     If Cmd%=3 then 'Close down Completed
  292.         MsgClose
  293.         MsgBox "Finishing saving group information",0,"Save 'A Group"
  294.     End if
  295.  
  296.  
  297. end sub
  298.  
  299.  
  300. /* **************************************************************************************
  301. *    Function:    SaveGroupNames
  302. *    Parameters:Grp$
  303. *    Purpose:    This converts the information received by GetGroups, into a list of groups
  304. *        in the file GROUPS.INI
  305. *    Notes:    The program will exclude any groups with the same name as your "Quick Access"
  306. *        Groups
  307. *
  308. *
  309. ******************************************************************************************/
  310.  
  311. sub SaveGroupNames(Grp$)
  312.  
  313.     a=0
  314.     b=1
  315.     c=1
  316.     QAGrp$=Ucase$(ReadIni$("Quick Access","MainGroup","NDW.INI"))
  317.     While (c<=len(Grp$))
  318.         
  319.         b=InStr(c,Grp$,",")
  320.         g$=Mid$(Grp$,c,b-c)
  321.         if (Ucase$(g$)<>QAGrp$) then
  322.             a=a+1
  323.             l$="GROUP"+Str$(a)
  324.             WriteIni "GROUPS",l$,encap$(g$),"GROUPS.INI"
  325.  
  326.         end if
  327.         c=b+1
  328.     Wend
  329.     WriteIni "GROUPS","TOTAL",Str$(a),"GROUPS.INI"
  330.     WriteIni "GROUPS","DATE",Date$(),"GROUPS.INI"
  331. end sub
  332.  
  333.  
  334.  
  335. /* **************************************************************************************
  336. *    Function:    SaveGroupData
  337. *    Parameters:Group$
  338. *    Purpose:    This saves the information for a specific group to the Groups.INI file
  339. *
  340. ******************************************************************************************/
  341.  
  342.  
  343. sub SaveGroupData(Group$)
  344.  
  345.     GroupInfo$=DDEget$(Group$)
  346.     
  347.     a=1
  348.     b=1
  349.     c=1
  350.     GroupInfo$ = Mid$(GroupInfo$,InStr(c,GroupInfo$,chr$(13))+1,len(GroupInfo$))
  351.     While (c<>len(GroupInfo$))
  352.         b=InStr(c,GroupInfo$,chr$(13))
  353.         g$=Mid$(GroupInfo$,c+1,b-c)
  354.         G$ = MakeNDWValid$(G$)
  355.         l$="Item"+Str$(a)
  356.         WriteIni Group$,l$,g$,"GROUPS.INI"
  357.         a=a+1
  358.         c=b+1        
  359.     Wend
  360.     WriteIni Group$,"TOTAL",str$(a-1),"GROUPS.INI"    
  361.  
  362. End Sub
  363.  
  364.  
  365. /* **************************************************************************************
  366. *    Function:    SaveGroupData
  367. *    Parameters:Group$
  368. *    Purpose:    This saves the information for a specific group to the Groups.INI file
  369. *
  370. ******************************************************************************************/
  371.  
  372. sub SaveAllGroups(Group$)
  373.  
  374.     
  375.     c=0
  376.     TotalGroups = Val ( ReadIni$("Groups","TOTAL","GROUPS.INI"))
  377.     InformUser 1,0
  378.     While (c<TotalGroups)
  379.         c=c+1
  380.         l$=Str$(c)
  381.         l$="GROUP"+l$
  382.         g$=ReadIni$("GROUPS",l$,"GROUPS.INI")
  383.         InformUser 2,int((c/TotalGroups)*100)
  384.         SaveGroupData(g$)
  385.     Wend
  386.     InformUser 3,0
  387. end sub
  388.  
  389. /* **************************************************************************************
  390. *    Function:    RestoreGroup
  391. *    Parameters:Group$
  392. *    Purpose:    This rebuilds the group based upon information for a specific group 
  393. *        in the Groups.INI file
  394. *
  395. ******************************************************************************************/
  396.  
  397. sub RestoreGroup(Group$)
  398.  
  399.  
  400.     Dim TotalItems as Integer
  401.     Dim CurrentItem as Integer
  402.     Dim L$ as String
  403.             
  404.     TotalItems=0
  405.     CurrentItem=0
  406.  
  407.     TotalItems = Val( ReadIni$(Group$,"TOTAL","GROUPS.INI") )
  408.  
  409.     If TotalItems >50 then
  410.         TotalItems = 50
  411.     End if
  412.  
  413.     If (TotalItems <> 0) then
  414.         Grp$ = Group$
  415.         CreateGroup (Grp$)
  416.         CurrentItem=1
  417.  
  418.         While (CurrentItem <= TotalItems)
  419.  
  420.             l$="Item"+Str$(CurrentItem)
  421.             Cmd$=ReadIni$(Group$,l$,"GROUPS.INI")
  422.             Comma1 = InStr(Cmd$,",")
  423.             Title$=Mid$(Cmd$,Comma1+1,InStr(Comma1+1,Cmd$,",")-Comma1-1)
  424.             AddItem Cmd$ 
  425.             CurrentItem=CurrentItem+1
  426.         Wend
  427.     End if
  428. end sub    
  429.  
  430. /* **************************************************************************************
  431. *    Function:    CheckRestore
  432. *    Parameters:None
  433. *    Purpose:    This confirm's whether the user is sure about the restore.
  434. *
  435. ******************************************************************************************/
  436.  
  437.  
  438. function CheckRestore(Msg$)
  439.  
  440.     GroupDate$ = ReadIni$("GROUPS","DATE","GROUPS.INI")
  441.  
  442.     Begin Dialog ConfirmDialog 125,26,214,158, "Confirm Restoration of Groups"
  443.         PushButton 30,120,60,20, "Continue"
  444.         CancelButton 129,120,60,20
  445.         Text 59,8,114,8, "Restoration of Groups"
  446.         Text 98,60,43,8, GroupDATE$
  447.         Text 10,30,96,8, "You are about to restore your"
  448.         Text 10,60,88,8, "groups was taken on the :"
  449.         Text 10,45,193,8, "from the GROUPS.INI file. The last Snapshot of your"
  450.         Text 107,30,100,8, Msg$
  451.         Text 11,82,174,8, "If you wish to proceed, then Click 'Continue'"
  452.         Text 11,95,174,8, "Otherwise, click on 'Cancel' to exit"
  453.     End Dialog
  454.  
  455.     Dim TmpDlg as ConfirmDialog
  456.  
  457.     CheckRestore=Dialog(TmpDlg)
  458.  
  459. end function
  460.  
  461.  
  462. /* **************************************************************************************
  463. *    Function:    RestoreAllGroup
  464. *    Parameters:None
  465. *    Purpose:    This rebuilds all the groups based upon information in the Groups.INI file
  466. *
  467. ******************************************************************************************/
  468.  
  469. sub RestoreAllGroups()
  470.  
  471.     Dim TotalGroups,CurrentGroup as Integer
  472.     Dim l$,Group$ as String
  473.  
  474.     TotalGroups=0
  475.     CurrentGroup=0
  476.  
  477.     TotalGroups = val( ReadIni$("GROUPS","TOTAL","GROUPS.INI"))
  478.  
  479.     if TotalGroups <> 0 then 
  480.  
  481.         if CheckRestore("program groups")<>0 then
  482.  
  483.             CurrentGroup=1
  484.             While (CurrentGroup<=TotalGroups)
  485.     
  486.                 l$="GROUP"+Str$(CurrentGroup)
  487.                 Group$ = ReadIni$("GROUPS",l$,"GROUPS.INI")
  488.                 Grp$ = Group$
  489.                 DeleteGroup Grp$
  490.                 Grp$ = Group$
  491.                 CreateGroup Grp$ 
  492.                 RestoreGroup Group$
  493.                 CurrentGroup=CurrentGroup+1
  494.             Wend
  495.         MsgBox "Finishing restoring group information",0,"Save 'A Group"
  496.         End If
  497.     End if
  498.  
  499. End Sub
  500.  
  501.  
  502. /* **************************************************************************************
  503. *    Function:    RestoreOneGroup
  504. *    Parameters:None
  505. *    Purpose:    This rebuilds one the groups based upon information in the Groups.INI file
  506. *
  507. ******************************************************************************************/
  508.  
  509. sub RestoreOneGroup()
  510.  
  511.     Dim GrpList$ (1 to 60)
  512.  
  513.     Begin Dialog RestDlg 176,32,135,157, "Restore One Group"
  514.         CancelButton 81,140,41,14
  515.         PushButton 10,140,52,14, "Restore"
  516.         ListBox 14,15,110,96, GrpList$, .GrpSelected
  517.         Text 3,120,128,15, "Select Group to restore then click on 'Restore' or 'Cancel' to exit."
  518.     End Dialog
  519.  
  520.  
  521.     Dim SelDlg as RestDlg
  522.  
  523.     TotalGroups=0
  524.  
  525.     TotalGroups = val( ReadIni$("GROUPS","TOTAL","GROUPS.INI"))
  526.  
  527.     if (TotalGroups <> 0) then
  528.         ReDim GrpList$ (1 to TotalGroups+1)
  529.         Counter = 0
  530.         While (Counter <=TotalGroups) 
  531.             Counter=Counter+1
  532.             Itm$ = "GROUP"+Str$(Counter)
  533.             GrpList$ (Counter) = ReadIni$("GROUPS",Itm$,"GROUPS.INI")
  534.         Wend
  535.         result=Dialog(SelDlg)
  536.         if (result<>0) then 
  537.             Group$=GrpList$(SelDlg.GrpSelected)
  538.             if (CheckRestore("the group "+group$+" from the")<>0) then 
  539.                 RestoreGroup(Group$)
  540.                 MsgBox "Finishing restoring group information",0,"Save 'A Group"
  541.             End if
  542.         End if
  543.         
  544.     End if
  545. end sub
  546.  
  547. /* **************************************************************************************
  548. *    Function:    main
  549. *    Parameters:None
  550. *    Purpose:    This is the main calling routine, execution starts here.
  551. *
  552. ******************************************************************************************/
  553.  
  554.         
  555. const IDB_CANCEL     = 0
  556. const IDB_SAVE        = 1
  557. const IDB_RESTORE_ONE    = 2
  558. const IDB_RESTORE_ALL    = 3
  559.  
  560. sub main()
  561.  
  562. ' Enable 3D Dialog box effects
  563.  
  564.  result=Ctl3dRegister(0)
  565.  if (result = 1) then
  566.   result=Ctl3dAutoSubClass(0)
  567.   Enable3D=1
  568.  end if
  569.  
  570.  On Error goto ErrorMsg
  571.  
  572.     Begin Dialog MenuDialog 53,45,358,137, "Save 'A Group"
  573.         CancelButton 280,100,70,20
  574.         PushButton 280,15,70,20, "Save All Groups"
  575.         PushButton 280,65,70,20, "Restore One Group"
  576.         PushButton 280,40,70,20, "Restore All Groups"
  577.         Text 99,31,57,8, "By Rob Harford"
  578.         Text 49,19,214,8, "Writen using the Symantec Scripting Language"
  579.         Text 100,8,75,8, "DDE Example program"
  580.         Text 20,100,254,8, "'Restore All Groups' will restore the backup made by using 'Save ALL Groups'"
  581.         Text 20,90,236,8, "'Save All Groups' will make a copy the groups  under your current shell."
  582.         Text 22,50,196,8, "This utility will save and restore groups from different shells"
  583.         Text 22,65,238,8, "This program will run under different shells (e.g NDW,Program Manager)"
  584.         Text 85,78,81,8, "------------------------------------"
  585.         Text 20,110,256,8, "'Restore One Group' will allow you to restore just one group from your backup"
  586.         Text 20,120,256,8, "'Cancel' will exit from this program"
  587.         Text 341,127,14,8, "1.4"
  588.     End Dialog
  589.  
  590.      Dim Dialog1 as  MenuDialog
  591.     
  592.     result =-1
  593.     While (Result<>0)
  594.         result = Dialog(Dialog1)
  595.         if result = IDB_SAVE then 
  596.             Group$ = GetGroup$()
  597.             Group$ = MakeComma$(Group$)
  598.             SaveGroupNames(Group$)
  599.             SaveAllGroups(Group$)
  600.         end if
  601.     
  602.         if result = IDB_RESTORE_ALL then
  603.             RestoreAllGroups
  604.         end if
  605.     
  606.         if result = IDB_RESTORE_ONE then
  607.             RestoreOneGroup
  608.         end if
  609.     Wend
  610.     Goto GoodEnd
  611.  
  612. ErrorMsg:
  613.     MsgBox "Sorry a Fatal Error occured"
  614.  
  615. GoodEnd:
  616.  
  617. ' Remove 3d Dialogs
  618.  if (Enable3D=1) then 
  619.    result=Ctl3dUnRegister(0)
  620.    Sleep 500
  621.  end if
  622.  
  623. end sub
  624.  
  625.